#ifndef __MMI_MS_H__
#define __MMI_MS_H__

#include "mmi_queue.h"
#include "mmi_com.h"

#define KEY_INPUT_MAX_LEN 32
#define PWD_INPUT_MAX_LEN 8
#define PWD_INPUT_MIN_LEN 6
#define PWD_INPUT_DECODE_RANDOM 15
#define PWD_INPUT_VIRTUAL_PWD 9
#define PWD_INPUT_SYNC_TIM_STAMP 10
#define FPS_MAX_INPUT_TIME OPT_FOUR_TIME

typedef enum
{
	SYS_STATUS_INIT = 0x00,

	SYS_STATUS_IDLE = 0x01,
	SYS_STATUS_INPUT_PWD = 0x01,
	SYS_STATUS_INPUT_ADMIN_PWD = 0x02,
	SYS_STATUS_ADD_PWD = 0x12,
	SYS_STATUS_DEL_PWD = 0x13,
	SYS_STATUS_CLR_PWD = 0x14,
	SYS_STATUS_ADD_PWD_CON = 0x15,
	SYS_STATUS_DEL_PWD_CON = 0x16,
	SYS_STATUS_ADD_110_PWD = 0x17,

#ifdef __LOCK_FP_SUPPORT__
	SYS_STATUS_INPUT_FP = 0x01,
	SYS_STATUS_INPUT_ADMIN_FP = 0x02,
	SYS_STATUS_ADD_FP = 0x22,
	SYS_STATUS_DEL_FP = 0x23,
	SYS_STATUS_CLR_FP = 0x24,
	SYS_STATUS_ADD_FP_CON = 0x25,
	SYS_STATUS_DEL_FP_CON = 0x26,
	SYS_STATUS_ADD_110_FP = 0x27,
	SYS_STATUS_DEL_110_FP = 0x28,
#endif

#ifdef __LOCK_RFID_CARD_SUPPORT__
	SYS_STATUS_INPUT_RFID = 0x01,
	SYS_STATUS_ADD_RFID = 0x32,
	SYS_STATUS_DEL_RFID = 0x33,
	SYS_STATUS_CLR_RFID = 0x34,
	SYS_STATUS_ADD_RFID_CON = 0x35,
	SYS_STATUS_DEL_RFID_CON = 0x36,
#endif

	SYS_STATUS_ADD_ADMIN_PWD = 0x41,
	SYS_STATUS_CHG_ADMIN_PWD = 0x42,
#ifdef __LOCK_FP_SUPPORT__
	SYS_STATUS_ADD_ADMIN_FP1 = 0x43,
	SYS_STATUS_ADD_ADMIN_FP2 = 0x44,
#endif

	SYS_STATUS_RESTORE_LOCK_CON = 0x50,
	SYS_STATUS_RESTORE_LOCK = 0x51,

	SYS_STATUS_DOOR_OPEN = 0x52,
	SYS_STATUS_SYS_MENU = 0x53,
	SYS_STATUS_FM_MODE = 0x54,
	SYS_STATUS_WIFI_MODE = 0x55,

	SYS_STATUS_WAIT_FOR_ENTER_SLEEP = 0x60,
	SYS_STATUS_ENTER_SLEEP = 0x61,

	SYS_STATUS_LOW_POWER = 0x70,

	SYS_STATUS_ADD_DECODE_RANDOM = 0x80,

	SYS_STATUS_INVALID = 0xFF,
} SYS_BASE_STATUS;

#ifdef __LOCK_VIRTUAL_PASSWORD__
typedef enum BASE_STATUS_MACHINE
{
	BASE_STATUS_M_IDLE,
	BASE_STATUS_M_IDLE_INPUT_PWD,
	BASE_STATUS_M_IDLE_SYS_MENU,
	//PWD
	BASE_STATUS_M_ADD_PWD,
	BASE_STATUS_M_ADD_PWD_AGAIN,
	BASE_STATUS_M_CHG_PWD,
	BASE_STATUS_M_CHG_PWD_AGAIN,
	BASE_STATUS_M_DEL_PWD,
	BASE_STATUS_M_DEL_PWD_AGAIN,
	BASE_STATUS_M_CLR_PWD,
//BASE_STATUS_M_CLR_PWD_END_OPT = 0x000A,
#if defined(__LOCK_FP_SUPPORT__) || defined(__LOCK_FP_SUPPORT2__) || defined(__LOCK_FP_SUPPORT1_2__)
	//FP
	BASE_STATUS_M_ADD_FP,
	BASE_STATUS_M_ADD_FP_AGAIN,
	BASE_STATUS_M_CHG_FP,
	BASE_STATUS_M_CHG_FP_AGAIN,
	BASE_STATUS_M_DEL_FP,
	BASE_STATUS_M_DEL_FP_AGAIN,
	BASE_STATUS_M_CLR_FP,
//BASE_STATUS_M_CLR_FP_AGAIN = 0x0012,
#endif
#ifdef __LOCK_RFID_CARD_SUPPORT__
	//RF
	BASE_STATUS_M_ADD_RFID,
	BASE_STATUS_M_ADD_RFID_AGAIN,
	BASE_STATUS_M_CHG_RFID,
	//BASE_STATUS_M_CHG_RFID_AGAIN = 0x0016,
	BASE_STATUS_M_DEL_RFID,
	BASE_STATUS_M_DEL_RFID_AGAIN,
	BASE_STATUS_M_CLR_RFID,
//BASE_STATUS_M_CLR_RFID_AGAIN = 0x001A,
#endif
//very admin fp or pwd
#if defined(__LOCK_FP_SUPPORT__) || defined(__LOCK_FP_SUPPORT2__) || defined(__LOCK_FP_SUPPORT1_2__)
//BASE_STATUS_M_VERY_ADMIN_FP = 0x001D,
//BASE_STATUS_M_VERY_ADMIN_FP_AGAIN = 0x001E,
#endif
	//BASE_STATUS_M_VERY_ADMIN_PWD = 0x0020,
	//BASE_STATUS_M_VERY_ADMIN_PWD_AGAIN = 0x0021,

	//for change
	//BASE_STATUS_M_INPUT_NEW_PWD = 0x0025,
	BASE_STATUS_M_INPUT_NEW_PWD_AGAIN,

	//end input pwd
	//BASE_STATUS_M_END_INPUT = 0x0027,
	//BASE_STATUS_M_PRE_INPUT = 0x0028,
	//BASE_STATUS_M_END_ADD_PWD = 0x0029,
	//BASE_STATUS_M_PRE_ADD_PWD = 0x002A,
	BASE_STATUS_M_ADD_PWD_INPUT,
	BASE_STATUS_M_ADD_PWD_AGAIN_INPUT,
	//BASE_STATUS_M_END_ADD_PWD_AGAIN = 0x002D,
	//BASE_STATUS_M_PRE_ADD_PWD_AGAIN = 0x002E,

	//menu opt
	BASE_STATUS_M_IDLE_SYS_MENU_OPT,

	//CHG PWD
	BASE_STATUS_M_CHG_PWD_INPUT_OLD,
	BASE_STATUS_M_CHG_PWD_INPUT_NEW_START,
	BASE_STATUS_M_CHG_PWD_INPUT_NEW,
	BASE_STATUS_M_CHG_PWD_INPUT_NEW_AGAIN_START,
	BASE_STATUS_M_CHG_PWD_INPUT_NEW_AGAIN,
	BASE_STATUS_M_ADD_PWD_CONFIRM_CON,
	BASE_STATUS_M_CHG_PWD_CONFIRM_CON,
	BASE_STATUS_M_DEL_PWD_CONFIRM_CON,
	BASE_STATUS_M_CHG_PWD_CON_INPUT,
	BASE_STATUS_M_ADD_PWD_CON_INPUT,
	BASE_STATUS_M_DEL_PWD_CON_INPUT,

	//del pwd
	BASE_STATUS_M_DEL_PWD_INPUT,
	BASE_STATUS_M_DEL_PWD_AGAIN_INPUT,
	BASE_STATUS_M_CONFIRM_INPUT_NUM,
	BASE_STATUS_M_DEL_PWD_CONFIRM_NUM_INPUT,
	//BASE_STATUS_M_DEL_PWD_INDEX = 0x0042,

	//clear pwd
	BASE_STATUS_M_CLR_PWD_CON,

	//init add admin pwd
	BASE_STATUS_M_INIT_ADD_ADMIN,
	BASE_STATUS_M_INIT_ADD_ADMIN_AGAIN,
	BASE_STATUS_M_INIT_ADD_ADMIN_INPUT,
	//BASE_STATUS_M_END_INIT_ADD_ADMIN_INPUT,
	//BASE_STATUS_M_PRE_INIT_ADD_ADMIN_INPUT,
	BASE_STATUS_M_INIT_ADD_ADMIN_INPUT_AGAIN,
	//BASE_STATUS_M_END_INIT_ADD_ADMIN_INPUT_AGAIN,
	//BASE_STATUS_M_PRE_INIT_ADD_ADMIN_INPUT_AGAIN,
	//BASE_STATUS_M_INIT_ADD_ADMIN_END_OPT,
	BASE_STATUS_M_IDLE_SYS_MENU_START,
	BASE_STATUS_M_IDLE_SYS_MENU_INPUT,
	//BASE_STATUS_M_PRE_IDLE_SYS_MENU,
	//BASE_STATUS_M_END_IDLE_SYS_MENU,
	//BASE_STATUS_M_IDLE_SYS_MENU_END_OPT,
	//init flash
	BASE_STATUS_M_INIT_FDS_SET,
	BASE_STATUS_M_INIT_FDS_PWD,
	BASE_STATUS_M_INIT_FDS_FP,
	BASE_STATUS_M_INIT_FDS_RF,
	BASE_STATUS_M_WRITE_DATA_CB,

	//write flash call back
	BASE_STATUS_M_ADD_ADMIN_STA_CB,
	//BASE_STATUS_M_IDLE_INPUT_END,
	//BASE_STATUS_M_DEL_PWD_NUM,
	//BASE_STATUS_M_DEL_PWD_NUM_CON_OPT,
	//BASE_STATUS_M_DEL_PWD_NUM_CON_HASH_OPT,

	//set pro mode
	BASE_STATUS_M_SET_PRO_SOUND,
	BASE_STATUS_M_CLR_PRO_SOUND,
	//set open mode
	BASE_STATUS_M_SET_SIN_OPEN_MODE,
	BASE_STATUS_M_SET_DBL_OPEN_MODE,

#if defined(__LOCK_FP_SUPPORT__) || defined(__LOCK_FP_SUPPORT2__) || defined(__LOCK_FP_SUPPORT1_2__)
	//fp add
	BASE_STATUS_M_ADD_FP_END,
	BASE_STATUS_M_ADD_FP_STAR,
	BASE_STATUS_M_ADD_FP_CONTINUE,
	BASE_STATUS_M_ADD_FP_CONTINUE_INPUT,
	BASE_STATUS_M_ADD_FP_PRESS_1,
	BASE_STATUS_M_ADD_FP_PRESS_2,
	//fp chg
	BASE_STATUS_M_CHG_FP_END,
	BASE_STATUS_M_CHG_FP_STAR,
	BASE_STATUS_M_CHG_FP_CONTINUE,
	BASE_STATUS_M_CHG_FP_CONTINUE_INPUT,
	BASE_STATUS_M_CHG_FP_NEW,
	BASE_STATUS_M_CHG_FP_PRESS_1,
	BASE_STATUS_M_CHG_FP_PRESS_2,
	BASE_STATUS_M_CHG_FP_PRESS_3,
	//fp del
	BASE_STATUS_M_DEL_FP_INPUT,
	//BASE_STATUS_M_DEL_FP_INPUT_CONFIRM,
	BASE_STATUS_M_DEL_FP_NUM,
	BASE_STATUS_M_DEL_FP_NUM_INPUT,
	BASE_STATUS_M_DEL_FP_CONTINUE,
	BASE_STATUS_M_DEL_FP_CONTINUE_INPUT,
	//BASE_STATUS_M_DEL_FP_END,
	BASE_STATUS_M_DEL_FP_PRESS_1,
	BASE_STATUS_M_DEL_FP_PRESS_2,
	BASE_STATUS_M_DEL_FP_STAR,
	//fp clr
	BASE_STATUS_M_CLR_FP_INPUT,
	BASE_STATUS_M_FP_OPEN_LOCK,

	//admin fp
	BASE_STATUS_M_ADD_ADMIN_FP1,
	BASE_STATUS_M_ADD_ADMIN_FP2,
	BASE_STATUS_M_ADD_ADMIN_FP1_AGAIN,
	BASE_STATUS_M_ADD_ADMIN_FP2_AGAIN,
	BASE_STATUS_M_ADD_ADMIN_FP1_END,
	BASE_STATUS_M_ADD_ADMIN_FP2_END,
	BASE_STATUS_M_ADD_ADMIN_FP_PRESS_1,
	BASE_STATUS_M_ADD_ADMIN_FP_PRESS_2,
	BASE_STATUS_M_ADD_ADMIN_FP_STAR,
#endif
	//restore lock
	BASE_STATUS_M_RESTORE_LOCK,
	BASE_STATUS_M_RESTORE_LOCK_INPUT,
	BASE_STATUS_M_RESTORE_SUC,

	//factory mode
	BASE_STATUS_M_FM_START,
#ifdef __LOCK_OLED_SUPPORT__
	BASE_STATUS_M_FM_RESULT,
	BASE_STATUS_M_FM_RESULT_OPT,
#endif
	BASE_STATUS_M_FM_KEY,
	BASE_STATUS_M_FM_KEY_INPUT,
#ifdef __LOCK_OLED_SUPPORT__
	BASE_STATUS_M_FM_KEY_LIGHT,
	BASE_STATUS_M_FM_KEY_LIGHT_INPUT,
	BASE_STATUS_M_FM_OLED,
	BASE_STATUS_M_FM_OLED_ON,
	BASE_STATUS_M_FM_OLED_RESULT,
	BASE_STATUS_M_FM_OLED_RESULT_INPUT,
#endif
#if defined(__LOCK_FP_SUPPORT__) || defined(__LOCK_FP_SUPPORT2__) || defined(__LOCK_FP_SUPPORT1_2__)
	BASE_STATUS_M_FM_FP,
	BASE_STATUS_M_FM_FP_PRESS_1,
	BASE_STATUS_M_FM_FP_AGAIN,
	BASE_STATUS_M_FM_FP_PRESS_2,
	BASE_STATUS_M_FM_FP_MATCH,
	BASE_STATUS_M_FM_FP_SUC,
	BASE_STATUS_M_FM_FP_FULL,
#endif
#ifdef __LOCK_RFID_CARD_SUPPORT__
	BASE_STATUS_M_FM_RF,
	BASE_STATUS_M_FM_RF_PRESS_1,
	BASE_STATUS_M_FM_RF_AGAIN,
	BASE_STATUS_M_FM_RF_PRESS_2,
	BASE_STATUS_M_FM_RF_MATCH,
	BASE_STATUS_M_FM_RF_SUC,
#endif
	BASE_STATUS_M_FM_MOTO,
#ifdef __NBDQIOT_PROJECT_B06_SUPPORT__
	BASE_STATUS_M_FM_MOTO_END,
#endif
	BASE_STATUS_M_FM_MOTO_INPUT,
#ifdef __LOCK_OLED_SUPPORT__
	BASE_STATUS_M_FM_SOUND,
	BASE_STATUS_M_FM_SOUND_INPUT,
#endif
	BASE_STATUS_M_FM_RESET,
	BASE_STATUS_M_FM_STAR,
	BASE_STATUS_M_FM_END,

	BASE_STATUS_M_AUTOTEST,

	BASE_STATUS_M_TOUCH_SET,
	BASE_STATUS_M_TOUCH_SET_INPUT,
	BASE_STATUS_M_TOUCH_TEST,
	BASE_STATUS_M_TOUCH_TEST_INPUT,

	//app start
	BASE_STATUS_M_APP_PWD_1,
	BASE_STATUS_M_APP_PWD_2,
	BASE_STATUS_M_APP_PWD_3,
	BASE_STATUS_M_APP_PWD_4,
	BASE_STATUS_M_APP_LOG_1,
	BASE_STATUS_M_APP_LOG_2,
	BASE_STATUS_M_APP_LOG_3,
	BASE_STATUS_M_APP_LOG_4,

	BASE_STATUS_M_APP_INIT_LOG, //146
	BASE_STATUS_M_APP_INIT_SET,
	BASE_STATUS_M_APP_INIT_PWD,
	BASE_STATUS_M_APP_INIT_FP,
	BASE_STATUS_M_APP_INIT_RF,
#ifdef __LOCK_RFID_CARD_SUPPORT__
	//RFID
	BASE_STATUS_M_RFID_STAR,
	BASE_STATUS_M_ADD_RFID_PRESS_1,
	BASE_STATUS_M_ADD_RFID_PRESS_2,
	BASE_STATUS_M_ADD_RFID_CONTINUE,
	BASE_STATUS_M_ADD_RFID_CON_INPUT,
	//chg rfid
	BASE_STATUS_M_CHG_RFID_PRESS_1,
	BASE_STATUS_M_CHG_RFID_PRESS_2,
	BASE_STATUS_M_CHG_RFID_PRESS_3,
	BASE_STATUS_M_CHG_RFID_NEW,
	BASE_STATUS_M_CHG_RFID_NEW_AGAIN,
	BASE_STATUS_M_CHG_RFID_CONTINUE,
	BASE_STATUS_M_CHG_RFID_CON_INPUT,
	//del rfid
	BASE_STATUS_M_DEL_RFID_INPUT,
	BASE_STATUS_M_DEL_RFID_NUM,
	BASE_STATUS_M_DEL_RFID_NUM_INPUT,
	BASE_STATUS_M_DEL_RFID_PRESS_1,
	BASE_STATUS_M_DEL_RFID_PRESS_2,
	BASE_STATUS_M_DEL_RFID_CONTINUE,
	BASE_STATUS_M_DEL_RFID_CON_INPUT,
	//clr rfid
	BASE_STATUS_M_CLR_RFID_INPUT,
	BASE_STATUS_M_RFID_OPEN_LOCK,
#endif
	//system enter sleep
	BASE_STATUS_M_ENTER_SLEEP,

	//save log
	BASE_STATUS_M_SAVE_LOG,
	BASE_STATUS_M_SAVE_LOG_WITH_CLOSE,

	//lock moto
	//BASE_STATUS_M_MOTOR_OPEN,
	//BASE_STATUS_M_MOTOR_DELAY,
	//BASE_STATUS_M_MOTOR_CLOSE,
	//lock
	BASE_STATUS_M_LOCK_CLOSE,
#ifdef __NBDQIOT_PROJECT_B06_SUPPORT__
	BASE_STATUS_M_LOCK_OPEN,
	BASE_STATUS_M_LOCK_OPEN_INPUT1,
	BASE_STATUS_M_LOCK_OPEN_INPUT2,
	BASE_STATUS_M_LOCK_OPEN2,
#endif
#ifdef __LOCK_OPEN_IF_NONE_FP__
	BASE_STATUS_M_LOCK_OPEN_1,
	BASE_STATUS_M_LOCK_OPEN_2,
#endif
#ifdef __PREIPHERAL_WIFI_UH010_SUPPORT__
	BASE_STATUS_WIFI_SETTING,
	BASE_STATUS_WIFI_CONNECTING,
	BASE_STATUS_WIFI_CON_FAIL,
	BASE_STATUS_WIFI_CON_SUC,
#endif
	BASE_STATUS_M_INVALID = 0xFFFF
} BASE_STATUS_MACHINE;

#define SHOW_MESSAGE_DELAY_TIME 2000
#define SHOW_MESSAGE_DELAY_TIME2 4000
#define OPEN_LOCK_DELAY_TIME 8000

#endif

typedef enum OPERATE_TIME
{
	OPT_ONE_TIME = 0x00,
	OPT_TWO_TIME = 0x01,
	OPT_THREE_TIME = 0x02,
	OPT_FOUR_TIME = 0x03,
	OPT_TIME_INVALID = 0xFF,
} OPERATE_TIME;

typedef enum
{
	MS_OPEN_MODE_SIN = 0,
	MS_OPEN_MODE_DBL = 1,
	MS_OPEN_MODE_INVALID = 0xFF
} ms_open_mode;

/*
parameter: 
	none
return :
	none
*/
void mmi_task_proc(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_sleep_task_proc(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_wait_sleep_task_proc(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_ms_pwd_init_var(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_ms_opt_time_init(void);

/*
parameter: 
	none
return :
	none
*/
unsigned char mmi_dq_ms_get_run_flag(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_dq_ms_sys_msg_handle(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_dq_ms_set_msg_que(SYS_QUEUE_EVENT q_event, SYS_QUEUE_PRO q_pro, unsigned char q_data);

/*
parameter: 
	none
return :
	none
*/
void mmi_dq_ms_set_sys_state(SYS_BASE_STATUS state);

/*
parameter: 
	none
return :
	none
*/
SYS_BASE_STATUS mmi_dq_ms_get_sys_state(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_ms_pwd_opt_fun(unsigned char key_val);

#ifdef __LOCK_FP_SUPPORT__
/*
parameter: 
	none
return :
	none
*/
void mmi_ms_fps_opt_fun(unsigned char fps_val);
#endif

#ifdef __LOCK_RFID_CARD_SUPPORT__
/*
parameter: 
	none
return :
	none
*/
void mmi_ms_rfid_opt_fun(unsigned char rfid_val);
#endif

/*
parameter: 
	none
return :
	none
*/
void mmi_ms_reset_opt_fun(void);

/*
parameter: 
	none
return :
	none
*/
void mmi_ms_wifi_opt_fun(void);

#endif //__MMI_MS_H__
